package com.neusoft.resturant.controller;

import com.neusoft.resturant.entity.Student;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import javax.swing.text.Style;

/**
 * @author: Daniel
 * @date: 2023-10-27 13:55
 **/
@RestController
@RequestMapping("/api/student")
public class StudentController {

    // http://localhost:8080/api/student?id=1
    @GetMapping
    public Student getStudent(HttpServletRequest request){
        String id = request.getParameter("id");
        System.out.println("id:"+ id);
        Student student = new Student();
        student.setId(Long.valueOf(id));
        // 1 调service
        // 2 service 调dao,dao 查询id为1的学生信息
        return student;
    }
    // http://localhost:8080/api/student/detail?id=1&sno=2&name=lisi
    @GetMapping("/detail")
    public Student getStudent1(Long id, String sno, String name){
        System.out.println("id:"+ id);
        System.out.println("sno:"+sno);
        System.out.println("name:"+name);
        Student student = new Student();
        student.setId(Long.valueOf(id));
        student.setSno(sno);
        student.setName(name);
        // 1 调service
        // 2 service 调dao,dao 查询id为1的学生信息
        return student;
    }

    // http://localhost:8080/api/student/getUserName?username=lisi
    @RequestMapping("/getUserName")
    public void getUserName(@RequestParam(value="username", required = false, defaultValue = "zhangsan") String name) {
            System.out.println("name="+name);
    }


    // http://localhost:8080/api/student/detail?id=1&sno=2&name=lisi
    @GetMapping("/detail1")
    public Student getDetail(Student student){
        // 1 调service
        // 2 service 调dao,dao 查询id为1的学生信息
        return student;
    }

}